--
-- Author:      feilong
-- DateTime:    2019-09-4 15:57:48
-- Description: 游戏主逻辑

local skynet = require("skynet")
local Timer = require("Timer")
local FSM = require("FSM")
local constant = require("constant")

--全局变量本地化
local math_floor = math.floor
local math_random = math.random
local math_abs = math.abs
local table_insert = table.insert
local table_remove = table.remove

local DeskBase = import("DeskBase")
local Desk = class("Desk",DeskBase)

--构造函数
function Desk:ctor()
	self.super:ctor()

end

----------------------------------------------------------------------------------------------
---------游戏
---------------------------------------------------------------------------------------------- 
function Desk:start()
	dbglog("___每日首充返利活动_开始了__")
	self.super.start(self) --基础的对象里在里面有初始化的了

	--数据初始化
	self:init()
	--状态时间
	self.state_time = {	
	
	}
	--游戏状态
	--state1 --eventName --state2 --callback
	self.state_list = {			
		{"rest",			"to_start",			"start", 		function() self:onStart() end },
		{"over",			"to_rest", 			"rest", 		function() self:onRest() end },
		{"start",			"to_over", 			"over", 		function() self:onOver() end },
	}
	self.fsm = FSM.new(self.state_list) --状态机
	--启动状态机
	self.fsm:set("over")
	self:changeState("to_rest")	


end

function Desk:init()
    self.open_time_list = {} --触发时间段
    self.act_data = self.config:getActivity()
    self.ac_content = self.act_data.ac_content
 
    self.test_id = 1000
end


--一局结束后重置数据
function Desk:reset()

    self.config:reload()
    self.act_data = self.config:getActivity()
    self.ac_content = self.act_data.ac_content
    self.user_manager:clear() --清掉玩家
end


function Desk:testOP()
    -- self.test_id = self.test_id + 1
    -- print("________test_id________", self.test_id)
    -- self:opPartakeNum(self.test_id, constant.DODULE_ID.FRIST_RECHARGE)
end

------------------------------------------------------------------
--state
------------------------------------------------------------------
function Desk:onRest()

    self:reset()  
    self:testOP()
    local function callback()
    	self:changeState("to_start")
		return false 	
    end
    self:setTimer(2, callback)
end

function Desk:onStart()
	self:testOP()
    local function callback()
    	self:changeState("to_over")
		return false 	
    end
    self:setTimer(2, callback)

end

--所有时间段结束了
function Desk:onOver()
	self:testOP()
    local function callback()
    	self:changeState("to_rest")
		return false 	
    end
    self:setTimer(2, callback)
end




return Desk